home *** CD-ROM | disk | FTP | other *** search
/ Technotools / Technotools (Chestnut CD-ROM)(1993).ISO / lang_c / m&tcga / prntinst.c < prev    next >
Text File  |  1988-04-30  |  2KB  |  99 lines

  1.                /*┌───────────────────────────────────────────────────────┐
  2.                  │                                                       │
  3.                  │   prntinst = installs graphics print screen routine   │
  4.                  │              to replace the original print screen     │
  5.                  │              routine.                                 │
  6.                  │                                                       │
  7.                  └───────────────────────────────────────────────────────┘*/
  8.  
  9. #include <dos.h>
  10.  
  11.  
  12. void interrupt print_handler()
  13. {
  14.     unsigned char background;
  15.         int i,x;
  16.  
  17.     void put_out(char character);
  18.  
  19.     put_out(0x1b);
  20.     put_out(0x33);
  21.     put_out(0x15);
  22.         for (i=0; i<12; i++)
  23.         put_out(0x0A);
  24.         background = readPixel(0,0);
  25.     for (x=319; x>=3; x-=4)
  26.             printrow(x,background);
  27.         put_out('\x0C');
  28. }
  29.  
  30.  
  31.  
  32. printrow(int x,int background)
  33. {
  34.     unsigned char savechar,temp;
  35.         unsigned char out_buff[485]={"\x1b*\x5\xE0\x01"};
  36.     int i, j, newy,y;
  37.  
  38.     char status();
  39.     void put_out();
  40.  
  41.     for (y=0,j=85; y<=199; y++,j+=2)
  42.     {
  43.         savechar = 0;
  44.         for (i=0; i<4; i++)
  45.         {
  46.             temp = readPixel(x-i,y);
  47.             if (temp != background)
  48.                 savechar |= 0x03;
  49.             if (i!=3)
  50.                 savechar <<= 2;
  51.         }
  52.         out_buff[j] = savechar;
  53.         out_buff[j+1] = savechar;
  54.      }
  55.     for (i=0; i<485; i++)
  56.     {
  57.         put_out(out_buff[i]);
  58.     }
  59.     put_out('\r');
  60.     put_out('\n');
  61. }
  62.  
  63. char status()
  64. {
  65.     char temp;
  66.     temp = inportb(0x379);
  67.     return (temp & 0x80);
  68. }
  69.  
  70.  
  71. void put_out(char character)
  72. {
  73.     int temp;
  74.     
  75.     while (!status());
  76.     outportb(0x378,character);
  77.     outportb(0x37A,0x0D);
  78.     outportb(0x37A,0x0C);
  79. }
  80.  
  81.  
  82. int readPixel (int x, int y)
  83. {    
  84.     char mask;
  85.     int color;
  86.     unsigned int offset;
  87.     offset = 0x2000 * (y%2) + 80 * (y/2) + x/4;
  88.         mask = peekb(0xB800,offset);
  89.     color = mask >> (6 - (x%4)*2) & 0x03;
  90.     return (color);
  91. }
  92.  
  93. main()
  94. {
  95.     setvect(5, print_handler);
  96.     printf("\nEGA Graphic Screen Printing Routine Installed\n");
  97.     keep(0,0x9FF);
  98. }
  99.